package com.cn.jinl.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cn.jinl.api.IHealthCheckService;
import com.cn.jinl.domain.HealthCheck;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * Created On : 2024/1/4.
 * <p>
 * Author : Huiyan
 * <p>
 * Description: 扩展应用---健康检疫
 */
@Controller
@RequestMapping("/healthCheck")
public class HealthCheckController {

    @Autowired
    private IHealthCheckService healthCheckService;

    @RequestMapping("/getHealthCheckList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<HealthCheck>> getHealthCheckList(@RequestBody QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<HealthCheck>> response = new JsonResponse<List<HealthCheck>>();
        List<HealthCheck> list  = healthCheckService.getHealthCheckList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }


    @RequestMapping("/getHealthCheckLogList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<HealthCheck>> getHealthCheckLogList(@RequestBody QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<HealthCheck>> response = new JsonResponse<List<HealthCheck>>();
        List<HealthCheck> list  = healthCheckService.getHealthCheckLogList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }



    @ResponseBody
    @RequestMapping("/uploadNewHealthCheck/{frontToken}")
    public JsonResponse<String> uploadNewHealthCheck(@RequestBody HealthCheck healthCheck,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = healthCheckService.uploadNewHealthCheck(healthCheck);
        return CommonUtil.getResponseData(response,result);
    }


    @ResponseBody
    @RequestMapping("/exportHealthCheckExcel")
    public void exportHealthCheckExcel(@RequestParam(value = "queryJson",required = true) String queryJson, HttpServletResponse response) throws Exception{
        QueryForm queryForm = new QueryForm();
        JSONObject jsonObject = JSON.parseObject(queryJson);

        queryForm.setJobCategory(jsonObject.getString("jobCategory"));
        queryForm.setDeptId(jsonObject.getString("deptId"));
        queryForm.setJobNumber(jsonObject.getString("jobNumber"));
        queryForm.setName(jsonObject.getString("name"));
        queryForm.setGender(jsonObject.getString("gender"));
        queryForm.setStatus(jsonObject.getString("status"));
        queryForm.setStartTime(jsonObject.getString("startTime"));
        queryForm.setEndTime(jsonObject.getString("endTime"));
        queryForm.setTaskStatus(jsonObject.getString("taskStatus"));

        healthCheckService.exportHealthCheckExcel(queryForm,response);
    }



}
